package com.action;

import com.bean.Student;
import com.bean.Teacher;
import com.dao.StudentDao;
import com.dao.TeacherDao;
import com.opensymphony.xwork2.ActionSupport;

public class RegisterAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = -4126728245446751398L;
	
	private Student stu;
	
	private Teacher tea;
	
	public String regist(){
		
		if(tea==null){
			StudentDao sd = new StudentDao();
			if(!sd.testStu(stu)){
				if(sd.addStu(stu)){
					return SUCCESS;
				}
			}else {
				this.addFieldError("registfailstu", "注册学生失败，用户账号已存在！");
				return SUCCESS;
				
			}
			//System.out.println(stu.getStuUserID());
		}else if(stu==null){
			TeacherDao td = new TeacherDao();
			if(!td.testTea(tea)){
				if(td.addTea(tea)){
					return SUCCESS;
				}
			}else {
				this.addFieldError("registfailtea", "注册教师失败，用户账号已存在！");
				return SUCCESS;
			}
		}
		return SUCCESS;
	}

	
	public void setStu(Student stu) {
		this.stu = stu;
	}

	public Student getStu() {
		return stu;
	}

	public void setTea(Teacher tea) {
		this.tea = tea;
	}

	public Teacher getTea() {
		return tea;
	}


}
